﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


namespace MyTestProject {
    class LambdaComparer<T> : EqualityComparer<T> {
        private readonly Func<T, T, bool> comparer;

        public LambdaComparer (Func<T, T, bool> comparer) {
            this.comparer = comparer;
        }

        public override bool Equals (T x, T y) {
            return comparer (x, y);
        }

        public override int GetHashCode (T x) {
            return comparer.GetHashCode ();
        }
    }

    class FloatComparere : EqualityComparer<float> {
        private readonly float tolerance;

        public FloatComparere (float tolerance) {
            this.tolerance = tolerance;
        }

        public override bool Equals (float x, float y) {
            return (Math.Abs (x - y) < tolerance) ? true : false;
        }

        public override int GetHashCode (float x) {
            return tolerance.GetHashCode ();
        }
    }

}
